package com.future.mayi.qsale.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;

import com.future.mayi.R;

/**
 * Created by Administrator on 2018/6/22.
 */

public class SalePhotoSampleDialog extends Dialog {

    private Context mContext;
    private ImageView ivQuit;
//    private TextView tvIntro;

    public SalePhotoSampleDialog(@NonNull Context context) {
        super(context, R.style.dialog);
        setContentView(R.layout.dialog_sale_photo_sample);
        setCancelable(true);
        this.mContext = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initDialogWidth();
//        tvIntro = (TextView) findViewById(R.id.tv_intro);
        ivQuit = (ImageView) findViewById(R.id.iv_quit);
        ivQuit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SalePhotoSampleDialog.this.dismiss();
            }
        });

//        new HttpRequest<DefaultResponse>()
//                .with(mContext)
//                .setApiCode(ApiCst.commonPzsyt)
//                .setListener(new HttpRequest.OnNetworkListener<DefaultResponse>() {
//                    @Override
//                    public void onSuccess(DefaultResponse response) {
//                        String responseString = "";
//                        try {
//                            JSONObject object = new JSONObject(response.content);
//                            responseString = object.optString("info");
//                            tvIntro.setText(Html.fromHtml(responseString));
//                        } catch (JSONException e) {
//                            e.printStackTrace();
//                        }
//                    }
//
//                    @Override
//                    public void onFail(String message) {
//                        ToastUtils.shortToast(mContext, message);
//                    }
//                })
//                .start(new DefaultResponse());
    }

    private void initDialogWidth() {
        Window window = getWindow();
        if (window == null) {
            return;
        }
        window.setDimAmount(0.8f); // 部分刷机会导致背景透明，这里保证一次
        WindowManager.LayoutParams wmlp = window.getAttributes();
        wmlp.width = ViewGroup.LayoutParams.MATCH_PARENT;
        window.setAttributes(wmlp);
    }
}
